<script>
iCMS.config.UI = '<!--{$iCMS.UI}-->';
</script>
  <link href="<!--{$iCMS.UI}-->/bootstrap/2.3.2/css/bootstrap-switch.css" type="text/css" rel="stylesheet"/>
  <script src="<!--{$iCMS.UI}-->/bootstrap/2.3.2/js/bootstrap-switch.min.js"></script>
  <script src="<!--{$iCMS.UI}-->/iCMS.user.editor-6.0.0.js" type="text/javascript" charset="utf-8"></script>
  <script src="<!--{$iCMS.UI}-->/ueditor/ueditor.all.min.js" type="text/javascript" charset="utf-8"></script>

<form action="<!--{iCMS:router url='/user'}-->" method="post" target="iCMS_FRAME">
    <input name="action" type="hidden" value="manage" />
    <input name="pg" type="hidden" value="publish" />
    <input name="id" type="hidden" value="<!--{$article.id}-->" />
    <input name="ucid" id="ucid" type="hidden" value="<!--{$article.ucid}-->" />
    <input name="_ucid" type="hidden" value="<!--{$article.ucid}-->" />
    <input name="_cid" type="hidden" value="<!--{$article.cid}-->" />
    <input name="mobile" type="hidden" value="0" />
    <div class="title"><span>发表文章</span></div>
    <div class="publish ml25">
      <div class="input-prepend"> <span class="add-on">栏 目</span>
        <select name="cid" id="cid" class="chosen-select span3">
          <option value="0"> == 请选择所属栏目 == </option>
          <!--{$option}-->
        </select>
      </div>
      <div class="input-prepend input-append"> <span class="add-on">快捷</span>
        <button class="btn btn-primary iCMS_user_publish" type="submit"><i class="fa fa-check"></i> 提交</button>
      </div>
      <div class="clearfix mb10"></div>
      <div class="input-prepend input-append"> <span class="add-on">标 题</span>
        <input class="span6" name="title" id="title" type="text" value="<!--{$article.title}-->">
        <div class="btn-group" id="user_category">
          <a class="btn dropdown-toggle" data-toggle="dropdown" tabindex="-1"> <span class="caret"></span> <span id="uc_select">默认分类</span></a>
          <ul class="dropdown-menu">
            <!--{iCMS:user:category loop="true" userid="$user.uid" appid="$iCMS.APPID.ARTICLE"}-->
            <li><a href="javascript:;" cid="<!--{$user_category.cid}-->" class="user_category"><!--{$user_category.name}--></a></li>
            <!--{/iCMS}-->
            <li id="user_category_0"><a href="javascript:;" cid="0" class="user_category">默认分类</a></li>
            <li class="divider"></li>
            <li><a href="javascript:;" title="添加分类" id="add_category" class="btn"><i class="fa fa-edit"></i> 添加分类</a></li>
          </ul>
        </div>
      </div>
      <div class="clearfix mb10"></div>
      <div class="input-prepend"> <span class="add-on">关键字</span>
        <input class="span6" name="keywords" id="keywords" type="text" value="<!--{$article.keywords}-->" onkeyup="javascript:this.value=this.value.replace(/，/ig,',');">
      </div>
      <div class="clearfix mb10"></div>
      <div class="input-prepend"> <span class="add-on">简 介</span>
        <textarea name="description" id="description" class="span6" style="height:150px;width:550px;padding:5px;"><!--{$article.description}--></textarea>
      </div>
      <div class="clearfix mb10"></div>
      <div class="input-prepend"> <span class="add-on">文章类型？</span>
        <div class="switch" id="article-type" data-on-label="原创" data-off-label="转贴"> <input type="checkbox" data-type="switch" name="creative" <!--{if $article.creative}-->checked<!--{/if}-->/> </div>
      </div>
      <div class="input-prepend <!--{if $article.creative}-->hide<!--{/if}-->" id="source-box"> <span class="add-on">出 处</span>
        <input class="span4" name="source" id="source" type="text" value="<!--{$article.source}-->">
      </div>
      <div class="clearfix mb10"></div>
      <script type="text/plain" id="editor" style="width:100%;height:360px;"><!--{$article_data.body}--></script>
      <div class="clearfix mb10"></div>
      <!--{if $iCMS.CONFIG.user.post.seccode }-->
      <div class="input-prepend"> <span class="add-on">验证码</span>
        <input type="text" maxlength="4" name="seccode" class="iCMS_post_seccode iCMS_seccode" data-placement="bottom">
        <img src="<!--{iCMS:router url='/api/public/seccode'}-->" alt="验证码" class="iCMS_seccode_img r3"/>
      </div>
      <a href="javascript:;" class="iCMS_seccode_text">换一张</a>
      <!--{/if}-->
      <div class="clearfix mb10"></div>
      <div class="form-actions">
        <button class="btn btn-large btn-primary iCMS_user_publish" type="submit"><i class="fa fa-check"></i> 提交</button>
      </div>
    </div>
  </form>
  <div id="add_category_box" style="display: none;">
    <input class="span3" id="newcategoryname" type="text" placeholder="请输入分类名称">
  </div>
  <script type="text/javascript">
var ed = UE.getEditor('editor');
$(function(){
	<!--{if $article.cid}-->
	$("#cid").val("<!--{$article.cid}-->");
	<!--{/if}-->
	<!--{if $article.ucid}-->
	var uc = $("[cid='<!--{$article.ucid}-->']");
	uc.parent().addClass('active');
	$("#uc_select").text(uc.text());
	<!--{/if}-->

	$(".iCMS_user_publish").click(function(){
		if($("#cid option:selected").val()=="0"){
			$("#cid").focus();
			iCMS.alert("请选择所属栏目");
			return false;
		}
		if($("#title").val()==''){
			$("#title").focus();
			iCMS.alert("标题不能为空!");
			return false;
		}
    <!--{if $iCMS.CONFIG.user.post.seccode }-->
    if($(".iCMS_post_seccode").val()==''){
      $(".iCMS_post_seccode").focus();
      iCMS.alert("验证码不能为空!");
      return false;
    }
    <!--{/if}-->
		if(!ed.hasContents()){
			ed.focus();
			iCMS.alert("内容不能为空!");
			return false;
		}
	});

	$('#article-type').on('switch-change', function (e, data) {
	    var value = data.value;
	    if(data.value){
	    	$('#source-box').hide();
	    	$('#source').val('');
	    }else{
	    	$('#source-box').css({
	    		display: 'inline-block',
	    	});
	    }
	});

	$(document).on('click', '.user_category', function(event) {
    	event.preventDefault();
		var $this = $(this),
		cid       = $this.attr("cid"),
		name      = $this.text();
        $("#ucid").val(cid);
        $("#uc_select").text(name);
        $(".user_category").parent().removeClass('active');
        $this.parent().addClass('active');
        $this.parent().parent().parent().removeClass("open");
        return false;
    });
    $('#add_category').click(function() {
      iCMS.dialog({
          follow: document.getElementById('user_category'),
          title: '添加新分类',
          content: document.getElementById('add_category_box'),
          okValue:'添加',
          ok: function () {
            var a = $("#newcategoryname"),n = a.val(),d=this;
            if(n==""){
              iCMS.alert("请输入分类名称!");
              a.focus();
              return false;
            }else{
              $.post('<!--{iCMS:router url='/user'}-->',{'action': 'add_category',name:n},
              function(j){
                if(j.code){
                  d.content(j.msg)
                  .button([{
                    value: '完成',
                    callback: function () {
                      $("#user_category_0").before('<li><a href="javascript:;" cid="'+j.forward+'" class="user_category">'+n+'</a></li>');
                    },autofocus: true
                  }]);
                }else{
                  alert(j.msg);
                  a.focus();
                  return false;
                }
              },"json");
            }
            return false;
          }
      });

    });

});
</script>
